/**
 * 保存字符串到本地存储
 */
export const saveString = (key: string, value: string): void => {
    window.localStorage.setItem(key,value);
}

/**
 * 从本地存储读取字符串内容, 如果不存在则返回空字符串
 */
export const getString = (key: string): string | "" => {
    return window.localStorage.getItem(key) ?? "";
}
/**
 * 保存对象到本地存储
 * @param key
 * @param value
 */
export const saveObject =<T extends object> (key: string, value: T): void => {
    window.localStorage.setItem(key, JSON.stringify(value));
}
/**
 * 从本地存储读取对象内容, 如果不存在则返回null
 */
export const getObject = <T> (key: string): T | null => {
    const value = window.localStorage.getItem(key);
    if(value){
        return JSON.parse(value);
    }
    return null;
}

